import Mock from "mockjs";
import { MockMethod } from "vite-plugin-mock";

// 指标列表数据
const indicatorList = [];
for (let i = 0; i < 20; i++) {
  indicatorList.push(
    Mock.mock({
      id: "@increment",
      name: `指标${i + 1}`,
      domain: ["XX指标域", "主题域一", "主题域二"][Math.floor(Math.random() * 3)],
      creator: "@cname",
      createTime: '@datetime("yyyy-MM-dd HH:mm:ss")',
      description: "@cparagraph(1, 3)",
    })
  );
}

// 指标树形结构数据
const indicatorTree = [
  {
    id: 1,
    label: "XX指标域",
    children: [
      {
        id: 11,
        label: "指标分组一",
        children: [
          { id: 111, label: "指标一" },
          { id: 112, label: "指标二" },
        ],
      },
      {
        id: 12,
        label: "指标分组二",
      },
    ],
  },
  {
    id: 2,
    label: "主题域一",
    children: [
      { id: 21, label: "主题表一" },
      { id: 22, label: "主题表二" },
    ],
  },
  {
    id: 3,
    label: "主题域二",
  },
];

// 拓扑图数据
const topologyData = {
  rootNode: {
    id: 1,
    name: "第一交易指标",
  },
  levelOneNodes: [
    {
      id: 11,
      name: "一级指标1",
      children: [
        { id: 111, name: "二级指标1.1" },
        { id: 112, name: "二级指标1.2" },
        { id: 113, name: "二级指标1.3" },
      ],
    },
    {
      id: 12,
      name: "一级指标2",
      children: [
        { id: 121, name: "二级指标2.1" },
        { id: 122, name: "二级指标2.2" },
        { id: 123, name: "二级指标2.3" },
      ],
    },
    {
      id: 13,
      name: "一级指标N",
      children: [
        { id: 131, name: "二级指标N.1" },
        { id: 132, name: "二级指标N.2" },
        { id: 133, name: "二级指标N.3" },
      ],
    },
  ],
};

export default [
  {
    url: "/api/indicator/list",
    method: "get",
    response: () => {
      return {
        code: 0,
        data: {
          items: indicatorList,
          total: indicatorList.length,
        },
        message: "success",
      };
    },
  },
  {
    url: "/api/indicator/tree",
    method: "get",
    response: () => {
      return {
        code: 0,
        data: indicatorTree,
        message: "success",
      };
    },
  },
  {
    url: "/api/indicator/topology",
    method: "get",
    response: () => {
      return {
        code: 0,
        data: topologyData,
        message: "success",
      };
    },
  },
  {
    url: "/api/indicator",
    method: "post",
    response: () => {
      return {
        code: 0,
        data: {
          id: Mock.mock("@increment"),
          createTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        },
        message: "success",
      };
    },
  },
  {
    url: /\/api\/indicator\/\d+/,
    method: "put",
    response: () => {
      return {
        code: 0,
        data: null,
        message: "success",
      };
    },
  },
  {
    url: /\/api\/indicator\/\d+/,
    method: "delete",
    response: () => {
      return {
        code: 0,
        data: null,
        message: "success",
      };
    },
  },
  {
    url: "/api/indicator/domain",
    method: "post",
    response: () => {
      return {
        code: 0,
        data: {
          id: Mock.mock("@increment"),
          createTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        },
        message: "success",
      };
    },
  },
  {
    url: "/api/indicator/group",
    method: "post",
    response: () => {
      return {
        code: 0,
        data: {
          id: Mock.mock("@increment"),
          createTime: Mock.mock('@datetime("yyyy-MM-dd HH:mm:ss")'),
        },
        message: "success",
      };
    },
  },
  {
    url: /\/api\/indicator\/\d+\/run/,
    method: "post",
    response: () => {
      return {
        code: 0,
        data: {
          result: true,
          executionTime: Mock.mock("@integer(100, 2000)"),
          message: "指标运行成功",
        },
        message: "success",
      };
    },
  },
  {
    url: /\/api\/indicator\/\d+\/test-run/,
    method: "post",
    response: () => {
      return {
        code: 0,
        data: {
          result: true,
          executionTime: Mock.mock("@integer(50, 500)"),
          message: "指标试运行成功",
          sampleData: Mock.mock({
            "list|5": [
              {
                date: '@date("yyyy-MM-dd")',
                value: "@float(100, 10000, 2, 2)",
                count: "@integer(10, 1000)",
              },
            ],
          }).list,
        },
        message: "success",
      };
    },
  },
] as MockMethod[];